#pragma once
namespace jxh {
	template<class T, class container = vector<T>, class compare = less<T>>
	class priority_queue {
	public:
		void adjustup(int child) {
			compare com;
			int parent = (child - 1) / 2;
			while (parent >= 0) {
				if (com(_con[child] , _con[parent])) {
					std::swap(_con[child], _con[parent]);
				}
				else break;
				child = parent;
				parent = (child - 1) / 2;
			}
		}
		void adjustdown(int parent) {
			compare com;
			int n = _con.size();
			int child = parent * 2 + 1;
			while (child < n) {
				if (child + 1 < n &&  com(_con[child + 1], _con[child]))child++;
				if (com(_con[child] , _con[parent]))std::swap(_con[child], _con[parent]);
				else break;
				parent = child;
				child = child * 2 + 1;
			}
		}
		void push(const T& x) {
			_con.push_back(x);
			adjustup(_con.size() - 1);
		}
		void pop() {
			std::swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			adjustdown(0);
		}
		const T& top() {
			return _con[0];
		}
		bool empty() {
			return _con.empty();
		}
		size_t size() {
			return _con.size();
		}

	private:
		container _con;
	};
}